package com.bawei.goods.hospital_goods.service.impl;

import com.bawei.common.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.bawei.goods.hospital_goods.dao.GoodTypeDao;
import com.bawei.goods.hospital_goods.entity.GoodTypeEntity;
import com.bawei.goods.hospital_goods.service.GoodTypeService;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.Query;

@Service("goodTypeService")
public class GoodTypeServiceImpl extends ServiceImpl<GoodTypeDao, GoodTypeEntity> implements GoodTypeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<GoodTypeEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (StringUtils.isNotEmpty(key)){
            wrapper.like("good_type", key);
        }
        wrapper.orderByAsc("good_sort");
        IPage<GoodTypeEntity> page = this.page(
                new Query<GoodTypeEntity>().getPage(params),
                wrapper

        );

        return new PageUtils(page);
    }

    @Override
    public void updateRow(String id, String row) {
        GoodTypeEntity byId = this.getById(id);
        byId.setGoodSort(Integer.parseInt(row));
        this.updateById(byId);
    }

}